//
// Created by user on 2022/1/18.
//
#include <iostream>
#include <vector>
using namespace std;
int candy(vector<int>& ratings) {
    int n = ratings.size();
    vector<int> left(n, 1);
    for (int i = 0; i < n; ++i) {
        if(i!=0 && ratings[i]> ratings[i-1]){
            left[i] = left[i-1]+1;
        }
    }

    vector<int> right(n, 1);
    for (int i = n-1; i>=0; --i) {
        if(i!=n-1&&ratings[i]>ratings[i+1]){
            right[i] = right[i+1]+1;
        }
    }

    vector<int> res(n,1);
    int sumVal = 0;
    for (int i = 0; i < n; ++i) {
        sumVal += fmax(left[i], right[i]);
    }
    return sumVal;
}

